package com.example.test.chapter7.custom_listview_collapsing_row;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class PhoneListAdapter extends BaseAdapter {
	Context mContext;
	private String[] mPhones = { "Samsung Galaxy Nexus ",
			"Samsung Galaxy S II Skyrocket ", "Motorola Droid Razr ",
			"Apple iPhone 4S ", "HTC Rezound " };
	private String[] mDetail = {
			"The Samsung Galaxy Nexus is a big step forward for Android, "
					+ "but it's not the giant leap you may have been expecting."
					+ "As impressive as it is, Ice Cream Sandwich can be messy, "
					+ "and without it, the Galaxy Nexus is just another Nexus device.",

			"If you live in an area that gets AT&T's LTE network, "
					+ "we highly recommend the powerful and beautiful ' +"
					+ "Samsung Galaxy S II Skyrocket.",

			"With its razor-thin design, jam-packed features, "
					+ "and blazing speed, the Motorola Droid Razr is "
					+ "easily one of the year's top Android smartphones.",

			"The iPhone 4S isn't the king of cell phones, "
					+ "but it's part of the royal family nonetheless.' +"
					+ "Even without 4G and a giant screen, this phone's smart "
					+ "voice assistant, Siri, the benefits of iOS 5, "
					+ "and its spectacular camera make it a top choice "
					+ "for anyone ready to upgrade.",

			"While it may have a hefty build, the HTC "
					+ "Rezound's beautiful display, commendable performance ,"
					+ "and multimedia-rich features make it a top phone "
					+ "for Verizon customers." };
	private boolean[] mExpanded = { false, false, false, false, false, false,
			false, false };

	public PhoneListAdapter(Context context) {
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return mPhones.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		PhoneView phoneView;
		if (convertView == null) {
			phoneView = new PhoneView(mContext, mPhones[position],
					mDetail[position], mExpanded[position]);
		} else {
			phoneView = (PhoneView) convertView;
			phoneView.setName(mPhones[position]);
			phoneView.setDetail(mDetail[position]);
			phoneView.setExpanded(mExpanded[position]);
		}
		return phoneView;
	}

	public void toggle(int position) {
		mExpanded[position] = !mExpanded[position];
		notifyDataSetChanged();
	}
}
